from ninja import Router

from apps.commom.package import AgentPackageSerializer
from apps.schemas import R
from models.models import AgentPackage
from utils.auth import AgentAuthBearer
from utils.constant import introduce_types
from utils.decorators import handle_exception
from utils.file_handler import load_json_file

agent_package_router = Router(tags=["代理套餐"], auth=AgentAuthBearer)


@agent_package_router.get("/equity_introduction", summary="获取代理权益介绍")
@handle_exception("获取代理权益介绍失败")
def get_equity_introduction(request):
    data = load_json_file(f"conf/{introduce_types.get('agent_package')}")
    return R.ok(data=data)


@agent_package_router.get("/packages", summary="获取代理套餐列表")
@handle_exception("获取代理套餐列表失败")
def get_packages(request):
    data = AgentPackage.objects.all()
    return R.ok(data=AgentPackageSerializer(data=data, many=True).data)
